package ca.etsmtl.log730.projet.view.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.swing.table.AbstractTableModel;

import org.apache.mina.core.session.IdleStatus;

import ca.etsmtl.log730.projet.controller.server.ServerClientChannelHandler;
import ca.etsmtl.log730.projet.model.user.User;

public class ChannelTableModel extends AbstractTableModel {
	@Override
	public String getColumnName(int column) {
		if(column == 0) return "ID";
		if(column == 1) return "SESSION";
		if(column == 2) return "IDLE";
		return "";
	}

	private Map<UUID, User> list = new HashMap<UUID, User>();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ChannelTableModel() {
		super();
	}
	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public Object getValueAt(int y, int x) {
		ArrayList<UUID> listUID = new ArrayList<UUID>(list.keySet());
		UUID ii = listUID.get(y);
		if(x == 0) return ii;
		if(x == 1) return list.get(ii).getSession().toString();
		if(x == 2) return list.get(ii).getSession().getIdleCount(IdleStatus.BOTH_IDLE);
		return "";
//		list.get(y).getSessionId();
	}

	public Map<UUID, User> getList() {
		return list;
	}

	public void setList(Map<UUID, User> list) {
		this.list = list;
	}

}
